package 网络.TCP;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TCPClient {

    public static void main(String[] args) throws Exception{
        // 创建客户端套接字
        Socket socket = new Socket("localhost", 8888);

        // 获取套接字输出流和输入流
        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        // 发送消息
        out.println("Hello, Server!");

        // 接收服务器的响应
        String response = in.readLine();
        System.out.println("Server response: " + response);

        socket.close();
    }
}
